package com.ywl.study.sharding.study06;

import com.ywl.study.sharding.common.enums.ShardingType;
import com.ywl.study.sharding.common.service.ExampleService;
import com.ywl.study.sharding.common.util.ExampleExecuteTemplate;
import com.ywl.study.sharding.study05.service.OrderServiceImpl;
import com.ywl.study.sharding.study06.factory.DataSourceFactory;

import javax.sql.DataSource;
import java.sql.SQLException;

public class JavaConfigurationExampleMain {

//        private static ShardingType shardingType = ShardingType.SHARDING_DATABASES;
//    private static ShardingType shardingType = ShardingType.SHARDING_TABLES;
//    private static ShardingType shardingType = ShardingType.SHARDING_DATABASES_AND_TABLES;
//    private static ShardingType shardingType = ShardingType.MASTER_SLAVE;
    private static ShardingType shardingType = ShardingType.SHARDING_MASTER_SLAVE;

    public static void main(final String[] args) throws SQLException {
        DataSource dataSource = DataSourceFactory.newInstance(shardingType);
        ExampleExecuteTemplate.run(getExampleService(dataSource));
    }

    private static ExampleService getExampleService(final DataSource dataSource) {
        return new OrderServiceImpl(dataSource);
    }
}
